const fs = require('fs');
const path = require('path');
const simpleGit = require('simple-git');


async function sync(folder) {
    try {
        console.log('syncing: ', folder);
        const git = simpleGit(folder, { binary: 'git' });
        await git.pull();
        console.log('success');
    } catch (err) {
        console.error(err.message);
    }
}


let basePath = '/home/szh/githelper/warehouse/';

async function start() {
    let items = await fs.promises.readdir(basePath);
    for (let item of items) {
        let stat = await fs.promises.stat(basePath + item);
        if (!stat.isDirectory()) continue;

        await sync(basePath + item);
    }

}


start();